package indi.kider.server.applandlord.api;

import indi.kider.common.model.employee.TenantQuery;
import indi.kider.common.model.employee.TenantQueryResponse;
import indi.kider.server.applandlord.service.related.HumanResources;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import pers.vankid.common.model.base.CommonResponse;
import pers.vankid.common.utils.page.PageRequest;
import pers.vankid.common.utils.page.PageResponse;

import java.util.List;

@RestController
@RequestMapping(value = "tenant", produces = "application/json;charset=UTF-8")
public class TenantController {
    @Autowired
    private HumanResources humanResources;

    /**
     * @api {PUT} tenant/main/{tenantId}
     * @apiGroup app-landlord
     * @apiDescription 设置主要承租人
     * @apiParamExample 请求样例：
     * http://localhost:9002/app-landlord/tenant/main/{tenantId}
     * @apiSuccessExample {json} 返回样例:
     * {"status":"202","msg":"保存成功！","data":""}
     */
    @PutMapping("main/{tenantId}")
    CommonResponse<String> setMainTenant(@PathVariable(value = "tenantId") Long tenantId) {
        return humanResources.setMainTenant(tenantId);
    }

    /**
     * @api {POST} tenant/rent/list
     * @apiGroup app-landlord
     * @apiDescription 根据租房信息查询租客列表（分页）
     * @apiParamExample 请求样例：
     * http://localhost:9002/app-landlord/tenant/rent/list
     * {"num":"0","size":"8","query":{"rentId":"223","name":"shixj2","cardId":12212,"phone":"1221","rentDateStart":"2018-05-15","rentDateEnd":"2018-05-15","expireDateStart":"2018-05-15","expireDateEnd":"2018-05-15"}}
     * @apiSuccessExample {json} 返回样例:
     * {"status":"200","msg":"查询成功！","data":{"rows":[{"rentDate":"2018-05-15","expireDate":"2018-05-15","id":76,"name":"shixj1","cardId":"12212","phone":"1221","title":null,"nationality":"32","professional":"23","wxopenId":null,"state":1,"type":2,"friendsSize":null,"mainId":69}],"total":1,"size":0}}
     */
    @PostMapping("rent/list")
    CommonResponse<PageResponse<List<TenantQueryResponse>>> getTenantList(@RequestBody PageRequest<TenantQuery> request) {
        return humanResources.getTenantList(request);
    }
}
